package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.SchoolAreaPojo;
import com.ruoyi.system.mapper.SchoolAreaMapper;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(tags = "校区管理")
@RestController
@RequestMapping("/api/schoolArea")
public class SchoolAreaController {

    @Autowired
    SchoolAreaMapper schoolAreaMapper;

    @PostMapping("/list")
    @ApiOperation("校区列表")
    public AjaxResult<List<SchoolAreaPojo>> listSchoolArea() {
        QueryWrapper<SchoolAreaPojo> query = new QueryWrapper<>();
        query.eq("status", 1);
        return AjaxResult.success(schoolAreaMapper.selectList(query));
    }

    @PostMapping("/add")
    @ApiOperation("新增校区")
    public AjaxResult addSchoolArea(@RequestBody SchoolAreaPojo schoolAreaPojo) {
        schoolAreaMapper.insert(schoolAreaPojo);
        return AjaxResult.success();
    }


    @PutMapping("/update")
    @ApiOperation("修改校区")
    public AjaxResult updateSchoolArea(@RequestBody SchoolAreaPojo schoolAreaPojo) {
        schoolAreaPojo.setUpdateTime(new Date());
        schoolAreaMapper.updateById(schoolAreaPojo);
        return AjaxResult.success();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除校区")
    public AjaxResult deleteSchoolArea(@PathVariable Integer id) {
        schoolAreaMapper.deleteById(id);
        return AjaxResult.success();
    }
}
